from flask import Flask, render_template
import pymysql
import sqlite3
import jieba  # 分词
from matplotlib import pyplot as plt  # 绘制
from wordcloud import WordCloud  # 词云
from PIL import Image  # 图片处理
import numpy as np  # 矩阵运算

app = Flask(__name__)


@app.route("/")
def home():
    return render_template("index.html")


@app.route("/index")
def index():
    return home()


@app.route("/movie")
def movies():
    datalist = []
    # 数据库访问
    conn = sqlite3.connect("movie.db")
    # conn = pymysql.connect(host='localhost', port=3306, user='root', password='wang9264', database='jing_dong',
    #                        charset='utf8')
    cur = conn.cursor()
    sql = 'select * from movie250'
    data = cur.execute(sql)
    print(data)
    for item in data:
        datalist.append(item)
    return render_template("movie.html", datalist=datalist)


@app.route("/score")
def scores():
    score = []  # 分数
    number = []  # 电影条数
    conn = sqlite3.connect("movie.db")
    cur = conn.cursor()
    sql = 'select score,count(score) from movie250 group by score'
    data = cur.execute(sql)
    for item in data:
        score.append(item[0])
        number.append(item[1])
    return render_template("score.html", score=score, number=number)


@app.route("/word")
def words():
    return render_template("word.html")


@app.route("/team")
def teams():
    return render_template("team.html")


if __name__ == '__main__':
    app.run()
